package com.ktjiaoyu.crm.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "sys_role")
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler"})
public class Role implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 编号
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "role_id")
	private Long roleId;

	/**
	 * 角色名称
	 */
	@Column(name = "role_name")
	private String roleName;

	/**
	 * 角色描述
	 */
	@Column(name = "role_desc")
	private String roleDesc;

	/**
	 * 状态
	 */
	@Column(name = "role_flag")
	private Long roleFlag;

	@OneToMany(targetEntity = User.class,
			fetch = FetchType.LAZY,
			cascade = CascadeType.PERSIST,mappedBy = "role")
	@JsonIgnore//Ignore(忽略)
	private Set<User> users = new HashSet<User>();
	// 多对多
	@ManyToMany(targetEntity = Right.class,fetch = FetchType.LAZY)
	@JoinTable(name = "sys_role_right",joinColumns = {@JoinColumn(name = "rf_role_id")},inverseJoinColumns = {@JoinColumn(name = "rf_right_code")})
	@OrderBy(value = "right_code")
	private Set<Right> rights = new HashSet<>(0);

}
